package com.by.controller;

import com.by.common.bean.ResultBean;
import com.by.common.core.controller.BaseController;
import com.by.common.token.TokenTemplate;
import com.by.entity.Spu;
import com.by.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/api/product")
@Api(tags = "SPU商品管理")
public class SpuController extends BaseController {

    @Autowired
    SpuService spuService;


    @ApiOperation("保存产品")
    @PostMapping("/spu")
    public ResultBean save(@Validated @RequestBody Spu spu, BindingResult result){
        validate(result);
        int rs=spuService.saveEntity(spu);
        return saveResult(rs);
    }

    @ApiOperation("商品详情")
    @GetMapping("/spu")
    public ResultBean get(@RequestParam(name = "id",required = true)int id ){
        Map map=spuService.getDetail(id);
        return success("商品详情",map);
    }


}
